import { Prefab,Node } from "cc";
import { SkillType } from "../utils/Config";
import { BulletSkillCtrl, SkillCtrl, SurroundSkillCtrl, TrackSkillCtrl } from "./SkillCtrl";


export class SkillPool
{
    public static instance : SkillPool = null;

    public static GetInstance()
    {
        if(SkillPool.instance == null)
        {
            SkillPool.instance = new SkillPool();
        }
        return SkillPool.instance;
    }

    private m_parent : Node = null;
    private m_allSkill : SkillCtrl[] = [];

    setParent(pn : Node)
    {
        this.m_parent = pn;
    }

    CreateSkill(skillId : SkillType,skillPfb : Prefab,heroNode : Node)
    {
        switch(skillId)
        {
            case SkillType.SurroundSkill :
                {
                    let skill = new SurroundSkillCtrl(skillId,skillPfb,heroNode);
                    this.m_allSkill.push(skill);
                    skill.initSkill();
                    break;
                }
            case SkillType.BulletSkill :
                {
                    let skill = new BulletSkillCtrl(skillId,skillPfb,heroNode,this.m_parent);
                    this.m_allSkill.push(skill);
                    break;
                }
            case SkillType.TrackSkill :
                {
                    let skill = new TrackSkillCtrl(skillId,skillPfb,heroNode,this.m_parent);
                    this.m_allSkill.push(skill);
                    break;
                }
        }
    }

    update(dt : number)
    {
        for(let i=0;i<this.m_allSkill.length;++i)
        {
            this.m_allSkill[i].update(dt);
        }
    }
}